﻿
{include file="../application/admin/view/common/header.html" /}
    <style type="text/css">
        .btn-blue,.btn-blue:hover,.btn-blue:focus{background-color: #3171b4;border-color: #3171b4;color:#ffffff;}
        .table-btn,.table-btn:hover,.table-btn:focus{border-radius: 2px;-webkit-border-radius: 2px;text-transform: capitalize;font-size: 13px;padding: 0px 4px;font-weight: 400;color: #666666;background-color: #c3c3c3;}
        .enable{color: #3171b4}
        .disable{color: #ff2929}
        .table{text-align: center;}
        .table thead{background-color: #aad4ff;}
        .table tbody{font-size: 13px;color: #333333;}
        .table tbody .buttons{padding: 3px;}
        .table thead{font-size: 14px;font-weight: bold;color: #111111;}
        .table thead th{text-align: center;}
    </style>
        <!--main content start-->
        <section class="main-content">


            <!--start page content-->

            <div class="row">
               
                 <div class="col-md-12">
                    <div class="panel panel-default collapsed">
                        <div class="panel-heading"> 
                            <a class="btn btn-danger ui-w" onclick="datadel()" href="javascript:void(0);"><span class="ui-icon ui-icon-trash"> </span>批量删除</a>
                            <a class="btn btn-blue ui-w" onclick="news_add(this)" href="javascript:void(0);"><span class="ui-icon ui-icon-plus"></span>添加政策</a>
                            <label for="name" style="color: #666666;font-size: 16px;font-weight: normal;line-height: 34px;margin: 3px 0;margin-left: 25px;">政策类别
                                <select style="height: 34px;border:1px solid #e0e0e0;width: 150px; " id="newsrole">
                                    <option value="0">所有</option>
                                    <option value="1">知识产权资助</option>
                                    <option value="2">知识产权奖励</option>
                                    <option value="3">维权奖励</option>
                                    <option value="4">企业奖励</option>
                                    <option value="5">项目奖励</option>
                                    <option value="6">金融补贴</option>
                                    <option value="7">知识产权运用奖励</option>
									<option value="8">知识产权保护奖励（贯标、商标注册）</option>
                                </select>
                            </label>
							<label class='hide' for="name" style="color: #666666;font-size: 16px;font-weight: normal;line-height: 34px;margin: 3px 0;margin-left: 25px;">类别子分类
                                <select style="height: 34px;border:1px solid #e0e0e0;width: 150px; " id="type">
                                    
                                    
                                </select>
                            </label>
							<label for="name" style="color: #666666;font-size: 16px;font-weight: normal;line-height: 34px;margin: 3px 0;margin-left: 25px;">地区
                                <select style="height: 34px;border:1px solid #e0e0e0;width: 150px; " id="area">
                                    <option value="0">所有</option>
                                    
                                </select>
                            </label>
							<label for="name" style="color: #666666;font-size: 16px;font-weight: normal;line-height: 34px;margin: 3px 0;margin-left: 25px;">区镇
                                <select style="height: 34px;border:1px solid #e0e0e0;width: 150px; " id="city">
                                    <option value="0">所有</option>
                                    
                                </select>
                            </label>
                            <div class="search-form">
                                <input type="text" class="form-control" placeholder="输入政策标题" />
                                <button type="button" class="btn-search" onclick="search_btn()"><i class="fa fa-search"></i></button>
                            </div>
                        </div>
                        <div class="panel-body">

                            <table class="table table-hover table-striped table-bordered" data-page-size="12" data-filter=#filter>
                                <thead>
                                <tr>
                                    <th>选择</th>
                                    <th>ID</th>
                                    <th>发布人</th>
                                    <th>政策内容</th>
                                    <th>政策类别</th>
                                    <th>文件编号</th>
									<th>城市</th>
									<th>区镇</th>
                                    <th>发布时间</th>
                                    <th>有效时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                    
                                                              
                                </tbody>
                            </table>
                            <div class="pager" id="page" style="text-align: right;"></div>
                         </div>
                    </div>
                </div>
            </div><!--end row-->
            
            <!--end page content-->



            <!-- <footer class="footer">
                <span></span>
            </footer> -->
       

        </section>
        <!--end main content-->



        <!--Common plugins-->
        <script src="_JS_/jquery.min.js"></script>
        <script src="_JS_/jquery.base64.js"></script>
        <script src="_JS_/jquery.cookie.js"></script>
        <script src="_JS_/bootstrap.min.js"></script>
        <script src="_JS_/jasny-bootstrap.min.js"></script>
        <script src="_JS_/jquery.slimscroll.min.js"></script>
        <script src="_JS_/jquery.nanoscroller.min.js"></script>
        <script src="_JS_/metismenu.min.js"></script>
        <script src="_JS_/float-custom.js"></script>
        <script type="text/javascript" src="_JS_/layer/layer.js"></script>
        <script type="text/javascript" src="_JS_/laypage/laypage.js"></script>
        <script type="text/javascript" src="_JS_/getMyDate.js"></script>
        <!-- <script src="js/footable.all.min.js"></script> -->
         <!-- Page-Level Scripts -->
    <script>

    $(function(){
        //获取登录信息
        var userinfo=$.cookie('username');
        if(userinfo!=null){
           var user_login= $.base64.decode(userinfo).split(",");
           $("#username").html(user_login[0]).attr("user_id",user_login[1]); 
        }else{
            window.location.href="{:url('admin/login/index')}";
        } 
        $("#page-title").html("政策信息");
        //新闻类别
        //加载管理员列表
		get_area();
        newslist(1); 

        //退出登录
        $('#bow_out').on('click',function(){
            $.cookie('username',"",{expires:-1,path:'/'});
            window.location.href="{:url('admin/login/index')}";
        }); 
    })
	function get_area(){
		$.ajax({ 
			type: "get", 
			url: "{:url('Api/policy/area')}",
			dataType: 'jsonp',
			jsonp:'callback',
			data: {'pid':1},
			success: function (msg) {
				if(msg.code == 200){
					for(var i=0;i<msg.data.length;i++){
						var html='<option value="'+msg.data[i].a_id+'">'+msg.data[i].name+'</option>';
						$("#area").append(html);
					}
				}
				if(msg.code==1000){
					layer.msg(msg.message,{icon:5,time:1000});
				}
			}
		}); 
	}
	$('#newsrole').on('change',function(){
		var pid=$(this).val();
		
		$.ajax({ 
			type: "get", 
			url: "{:url('Api/policy/type')}",
			dataType: 'jsonp',
			jsonp:'callback',
			data: {'pid':pid},
			success: function (msg) {
		
				if(msg.code == 200){
					$("#type").parent().removeClass('hide');
					$("#type").html('<option value="0">所有</option>');
					for(var i=0;i<msg.data.length;i++){
						var html='<option value="'+msg.data[i].t_id+'">'+msg.data[i].name+'</option>';
						$("#type").append(html);
					}
					
				}
				if(msg.code==1000){
					$("#type").parent().addClass('hide');
					//layer.msg(msg.message,{icon:5,time:1000});
				}
				newslist(1);
			}
		});
	})
	$('#area').on('change',function(){
		var pid=$(this).val();
		
		$.ajax({ 
			type: "get", 
			url: "{:url('Api/policy/area')}",
			dataType: 'jsonp',
			jsonp:'callback',
			data: {'pid':pid},
			success: function (msg) {
				if(msg.code == 200){
					$("#city").parent().removeClass('hide');
					$("#city").html('<option value="0">所有</option>');
					for(var i=0;i<msg.data.length;i++){
						var html='<option value="'+msg.data[i].a_id+'">'+msg.data[i].name+'</option>';
						$("#city").append(html);
					}
					newslist(1);
				}
				if(msg.code==1000){
					$("#city").html('<option value="0">所有</option>');
					newslist(1);
					//layer.msg(msg.message,{icon:5,time:1000});
				}
			}
		});
	})
    //获取新闻列表
    function newslist(page){
        var newsrole=$('#newsrole').val();
		var sort=$('#type').val();
		var area=$('#area').val();
		var city=$('#city').val();
		var search=$('input[type="text"]').val();
            $.ajax({ 
            type: "get", 
            url: "{:url('api/policy/policy_list')}",
            dataType: 'jsonp',
            jsonp:'callback',
            data: {'page':page,'search':search,'type':newsrole,'sort':sort,'area':area,'city':city},
            beforeSend: function () { 
                var index = layer.load(1, {
                  shade: [0.1,'#333333'] //0.1透明度的白色背景
                });
            }, 
            success: function (msg) { 
                layer.closeAll();
                $("#new_management").addClass("active").children("ul").addClass("in");
                $("#government_management").addClass("choose");
                if(msg.code == 200){ 
                    var pages=Math.ceil(msg.data.count/10);
                    $(".table tbody").html("");
                    if(msg.data.data.length>0){
                        for(var i=0;i<msg.data.data.length;i++){
                            var time = msg.data.data[i].time;
                                ltime=getMyDate(time*1000);
                            var html='<tr id="'+msg.data.data[i].id+'">';
                            html+='<td><input type="checkbox" name="allcheck"></td>';
                            html+='<td>'+msg.data.data[i].id+'</td><td>'+msg.data.data[i].username+'</td>';
                            html+='<td>'+msg.data.data[i].content+'</td>';
                            html+='<td>'+msg.data.data[i].name+'</td><td>'+msg.data.data[i].paper+'</td><td>'+msg.data.data[i].area1+'</td><td>'+msg.data.data[i].area2+'</td><td>'+ltime+'</td>';
							html+='<td>'+msg.data.data[i].stime+'</td>';
                            if(msg.data.data[i].status==2){
                            html+='<td class="td-status enable" status="1">已发布</td>';
                            html+='<td class="buttons td-manage"><a class="btn table-btn " onClick="news_down(this)" href="javascript:;" title="下架"><i class="fa fa-cloud-download"></i></a>';
                            }else if(msg.data.data[i].status==1){
                                 html+='<td class="td-status disable" status="2">未发布</td>';
                            html+='<td class="buttons td-manage"><a class="btn table-btn" onClick="news_up(this)" href="#"><i class="fa fa-cloud-upload enable" title="发布"></i></a>';
                            }
                            html+='<a class="btn table-btn" onclick="news_edit(this)" href="#" title="编辑"><i class="fa fa-pencil"></i></a><a class="btn table-btn" onclick="news_del(this)" href="#" title="删除"><i class="fa fa-trash-o"></i></a></td></tr>';
                            $(".table tbody").append(html);
                            $(".table").attr("pages",page);
                            //分页
                            laypage({
                                cont: 'page',
                                pages: pages,
                                curr:page,
                                jump: function(obj,first){
                                   if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
                                        newslist(obj.curr);
                                    }       
                                }
                            })
                        }
                    }else{
                        $('#page').hide();
                         $(".table tbody").append('<tr><td colspan="10">没有相关数据</td></tr>');
                    }                    
                } else{
                    layer.msg(msg.message,{icon:5,time:1000});
                }
                // if (msg.code == 1000) {
                //     alert("加载信息失败！");
                // }
            },            
        });
    }
    

    /*添加*/
    function news_add(obj){
        var uid="#"+$("#username").attr("user_id");
        var index=layer.open({
            type: 2,
            title: '添加新闻',
            content:'policy_add.html'+ uid
        }); 
        layer.full(index);
    }

    //编辑
    function news_edit(obj){
        var id="#"+$(obj).parents("tr").attr("id");
            uid="#"+$("#username").attr("user_id");
        var index=layer.open({
            type: 2,
            title: '编辑',
            content:'policy_edit.html'+ id +uid
        }); 
        layer.full(index);
    }

    /*发布*/
    function news_up(obj){
        layer.confirm('确认要发布吗？',function(index){
            var id=$(obj).parents("tr").attr("id");
                pages_num=$(".table").attr("pages");
            $.ajax({ 
                type: "get", 
                url: "{:url('Api/policy/status_edit')}",
                dataType: 'jsonp',
                jsonp:'callback',
                data: {'id':id,'status':'2'},
                success: function (msg) {
                    if(msg.code == 200){
                        $(obj).parents("tr").find(".td-manage").prepend('<a class="btn table-btn " onClick="news_down(this)" href="javascript:;" title="下架"><i class="fa fa-cloud-download"></i></a>');
                        $(obj).parents("tr").find(".td-status").html('已发布').attr("status",1);;
                        $(obj).parents("tr").find(".td-status").addClass("enable").removeClass("disable");
                        $(obj).parents("tr").remove();
                        newslist(pages_num);
                        layer.msg('已发布!',{icon:1,time:1000});
                    }
                    if(msg.code==1000){
                        layer.msg(msg.message,{icon:5,time:1000});
                    }
                }
            });             
        });
    }

    /*下架*/
    function news_down(obj){
        layer.confirm('确认要下架吗？',function(index){
            var id=$(obj).parents("tr").attr("id");
                pages_num=$(".table").attr("pages");
            $.ajax({ 
                type: "get", 
                url: "{:url('Api/policy/status_edit')}",
                dataType: 'jsonp',
                jsonp:'callback',
                data: {'id':id,'status':'1'},
                success: function (msg) {
                    if(msg.code == 200){
                        $(obj).parents("tr").find(".td-manage").prepend('<a class="btn table-btn" onClick="news_up(this)" href="#"><i class="fa fa-cloud-upload enable" title="发布"></i></a>');
                        $(obj).parents("tr").find(".td-status").html('已下架').attr("status",2);
                        $(obj).parents("tr").find(".td-status").addClass("disable").removeClass("enable");
                        $(obj).parents("tr").remove();
                        newslist(pages_num);
                        layer.msg('已下架!',{icon:1,time:1000});
                    }
                    if(msg.code==1000){
                        layer.msg(msg.message,{icon:5,time:1000});
                    }
                }
            }); 
        });
    }

    /*删除*/
    function news_del(obj){
        layer.confirm('确认要删除吗？',function(index){
            var id=$(obj).parents("tr").attr("id");
                pages_num=$(".table").attr("pages");
            $.ajax({ 
                type: "get", 
                url: "{:url('Api/policy/status_edit')}",
                dataType: 'jsonp',
                jsonp:'callback',
                data: {'id':id,'status':'3'},
                success: function (msg) {
                    if(msg.code == 200){
                        $(obj).parents("tr").remove();
                        newslist(pages_num);
                        layer.msg('已删除!',{icon:1,time:1000});
                    }
                    if(msg.code==1000){
                        layer.msg('删除失败!',{icon:5,time:1000});
                    }
                }
            });
        });
    }

    //回车键绑定搜索
    /**$(".search-form").keydown(function(event){ 
        if(event.keyCode==13){ 
          search_btn(); 
        }
    });
    $("#newsrole").change(function(){
        search_btn();
    });*/
	$("#type").change(function(){
        search_btn();
    });
	$("#city").change(function(){
        search_btn();
    });

    //搜索
    function search_btn(){
        newslist(1);
    }


    /*批量删除*/
     function datadel(){
        var arrs=new Array();
        $(".table input[name='allcheck']:checked").each(function(){ 
            arrs.push($(this).parents('tr').attr('id'));
        });
        if(arrs.length==0 ){
            layer.msg('请选择删除项!',{icon:1,time:1000});
            return false;
        }
        var uids=arrs.join(",");
        layer.confirm('确认要删除多个新闻吗？',function(index){
            var pages_num=$(".table").attr("pages");
            $.ajax({ 
                type: "get", 
                url: "{:url('Api/policy/status_edit')}",
                dataType: 'jsonp',
                jsonp:'callback',
                data: {'id':uids,'status':'3'},
                success: function (msg) {
                    if(msg.code == 200){ 
                        $(".table input[name='allcheck']:checked").parents('tr').remove();
                        newslist(pages_num);
                        layer.msg('已删除!',{icon:1,time:1000});
                    }
                    if(msg.code==1000){
                        layer.msg('删除失败!',{icon:5,time:1000});
                    }
                }
            });                       
        });
     }


    </script>
    </body>
</html>